home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / utilit~1 / initsnb.zoo / init / sh / dump < prev    next >
Encoding:
Text File  |  1992-09-09  |  3.3 KB  |  108 lines

  1. #!/bin/sh
  2. # make incremental dump of filesystems
  3. # usage: dump [+dont-compress] level filesystem...
  4. #
  5. # Dumps are made on $dumpdev, which contains a directory for every filesystem
  6. # dumped.  Of course, you cannot dump that filesystem itself.  For example,
  7. # if dumpdev=/dev/g, there will be the following directories:
  8. #   /dev/g/c
  9. #   /dev/g/d
  10. # et cetera.  Each such directory contains a file named YYYYMMDD.tar, where
  11. # YYYYMMDD is the date of the dump.  If you dump /dev/c on 03 May, 1992,
  12. # there will be a file /dev/g/c/19920503.tar
  13. version="0.0 alpha"
  14. PATH=${root}/bin:${root}/usr/bin
  15. set -e
  16. set -x # Uncomment this line when debugging
  17. umask 022
  18. dumpdev=/dev/g
  19. root=u:
  20. datesfile=${root}/etc/dumpdate
  21. infofile=${root}/etc/dumpinfo
  22.  
  23. fatalerror () {
  24.   echo Dump aborted on `date +"%m/%d/%Y %H:%M:%S"` due to a signal >> $infofile
  25. }
  26.  
  27. usage () {
  28.   echo usage: $program \[+dont-compress\] level partition...
  29. }
  30.  
  31. # Print message on fatal signal
  32. trap fatalerror 2 3 4 5 6 7 8 10 11 12 13 15
  33.  
  34. echo Dump script version $version, Stephan Neuhaus for MiNT/TOS
  35. program=`basename $0`
  36.  
  37. if test $# -le 1 -o \( $1 = +dont-compress -a $# -le 2 \) ; then
  38.   usage
  39.   exit 1
  40. fi
  41.  
  42. do_compress=1
  43. if test $1 = +dont-compress ; then
  44.   do_compress=0
  45.   shift
  46. fi
  47.  
  48. level=$1 ; shift
  49.  
  50. if test ! -d $dumpdev -a ! -b  $dumpdev ; then
  51.   echo program: Dump device $dumpdev: not a directory nor block special file
  52.   exit 1
  53. fi
  54.  
  55. for dumpdir in $* ; do
  56.   filesystem=/dev/${dumpdir}
  57.   if test ! -d $filesystem -a ! -b $filesystem ; then
  58.     echo $program: Source $filesystem: not a directory nor block special file
  59.     exit 1
  60.   fi
  61.   
  62.   if test $level -ne 0 ; then
  63.     lastdate=`gawk '
  64.       BEGIN { found = 0 }
  65.       $1 == level - 1 && $6 == filesystem { lastdate=$4; lasttime=$5; found=1 }
  66.       END { if (found) printf "%s %s", lastdate, lasttime; }' \
  67.       level=${level} filesystem=${filesystem} ${datesfile}`
  68.  
  69.       if test "x${lastdate}" = x ; then
  70.         echo Previous dump not found in ${datesfile}
  71.         exit 1
  72.       fi
  73.   fi
  74.   startdate=`date +"%m/%d/%Y %H:%M:%S"`
  75.   dumpdate=`echo $startdate | cut --delimiter=' ' --fields=1 | gawk -F / '{printf "%s%s%s", $3, $1, $2}'`
  76.   echo Begin of dump info for level $level dump of $filesystem >> $infofile
  77.   echo Level $level dump of $filesystem started on $startdate >> $infofile
  78.   echo -n Dumping $filesystem...
  79.   dumpfile=${dumpdev}/${dumpdir}/${dumpdate}.tar
  80.   if test ! -d ${dumpdev}/${dumpdir} ; then
  81.     mkdir ${dumpdev}/${dumpdir}
  82.   fi
  83.   cd $filesystem
  84.   if test $level -eq 0 ; then
  85.     tar +create +file $dumpfile .
  86.   else
  87.     tar +create +newer "$lastdate" +file $dumpfile .
  88.   fi
  89.   enddate=`date +"%m/%d/%Y %H:%M:%S"`
  90.   echo $level $startdate $enddate $filesystem >> ${datesfile}
  91.   echo -n Writing filelist...
  92.   echo List of files follows: >> $infofile
  93.   tar +list +verbose +file $dumpfile >> $infofile
  94.   echo Level $level dump of $filesystem ended on $enddate \(written on ${dumpfile}\) >> $infofile
  95.   ls -l $dumpfile >> $infofile
  96.   if test $do_compress -eq 1 ; then
  97.     echo -n Compressing...
  98.     compress -f $dumpfile
  99.     cfile=`echo $dumpfile | sed s/tar/taz/g`
  100.     ls -l $cfile >> $infofile
  101.   else
  102.     ls -l $dumpfile >> $infofile
  103.   fi
  104.   echo End of dump info for level $level dump of $filesystem >> $infofile
  105.   echo Done.
  106. done
  107. echo Done.
  108.